home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Devices / SCSI Simple Sample / Src / DoReadBlockZero.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  1.7 KB  |  57 lines  |  [TEXT/KAHL]

  1. /*                                    DoReadBlockZero.c                            */
  2. /*
  3.  * DoReadBlockZero.c
  4.  * Copyright © 1992-94 Apple Computer Inc. All Rights Reserved.
  5.  * Read the first block off of the SCSI Device.
  6.  */
  7. #include "SCSISimpleSample.h"
  8.  
  9. /*
  10.  * Read block zero from the indicated device..
  11.  */
  12. void
  13. DoReadBlockZero(
  14.         DeviceIdent                scsiDevice                /* -> Bus/target/LUN    */
  15.     )
  16. {
  17.         ScsiCmdBlock                    scsiCmdBlock;
  18.         unsigned long                    transferLength;
  19. #define SCB    (scsiCmdBlock)
  20.         
  21.         ShowSCSIBusID(scsiDevice, "\pRead Block Zero");
  22. #define kLogicalBlockLength    512
  23. #define kNumberOfBlocks        1
  24.         /*
  25.          * Note: this is slightly incorrect - it presumes that the device logical
  26.          * block length is 512 bytes. The correct algorithme would have first
  27.          * issued a Drive Capacity command to get the actual logical block length.
  28.          * This would be stored in a per-drive information record.
  29.          */
  30.         transferLength = kNumberOfBlocks * kLogicalBlockLength;
  31.         CLEAR(SCB);
  32.         SCB.scsiDevice = scsiDevice;
  33.         /*
  34.          * The 6-byte read command can read up to 128 blocks of data (1-127
  35.          * reads that number of blocks, while zero reads 128 blocks). For more
  36.          * flexibility, you should use the 10-byte Read command.
  37.          */
  38.         SCB.command.scsi6.opcode = kScsiCmdRead6;
  39.         SCB.command.scsi6.len = transferLength / kLogicalBlockLength;
  40.         SCB.bufferPtr = NewPtrClear(transferLength);
  41.         if (SCB.bufferPtr == NULL)
  42.             LOG("\pNo Memory for ReadBlockZero data buffer");
  43.         else {
  44.             SCB.transferSize = transferLength;
  45.             SCB.transferQuantum = kLogicalBlockLength;
  46.             DoSCSICommandWithSense(&scsiCmdBlock, TRUE, TRUE);
  47.             if (SCB.status == noErr)
  48.                 DisplayLogString(gLogListHandle, "\pRead was successful");
  49.             /*
  50.              * Here's where we can look at the data.
  51.              */
  52.             DisposePtr(SCB.bufferPtr);
  53.         }
  54. #undef SCB
  55. }
  56.  
  57.